import { useState } from "react"

interface EapModelDataType {
  eapOnline: boolean
  dataJsonSend: any
  dataJsonReceive: any
  response_result: any
  return_code: any
  return_msg: any
  serverEapParams: any
  serverDownRecipeTasks: any
  dataParseResult: any
  eapOrders: any[]
}

export default function eapModel() {
  const initData: EapModelDataType = {
    eapOnline: false,
    dataJsonSend: null,
    dataJsonReceive: null,
    response_result: null,
    return_code: null,
    return_msg: null,
    serverEapParams: null,
    serverDownRecipeTasks: null,
    dataParseResult: ["无响应", "", "", {}],
    eapOrders: []
  }

  const [eapData, setEapData] = useState<EapModelDataType>(initData)

  const updateEapData = (newData: Partial<EapModelDataType>) => {
    setEapData((prevData) => ({ ...prevData, ...newData }))
  }

  return {
    ...eapData,
    updateEapData
  }
}
